package app.objectstoragedemo.Pojo.CopyUtils;


import app.objectstoragedemo.Pojo.Mapper.FileStorage;
import app.objectstoragedemo.Pojo.Vo.UploadFileVo;

import javax.activation.MimetypesFileTypeMap;

public abstract class CopyFileUtils {
    private static String getShowUuid(String uuid) {
        // 要保证 controller 的 showFile 方法是这个 'show/' 请求
        return "/show/" + uuid;
    }

    private static String getDownloadUuid(String uuid) {
        // 要保证 controller 的 showFile 方法是这个 'show/' 请求
        return "/download/" + uuid;
    }

    private static String getDeleteUuid(String uuid) {
        // 要保证 controller 的 showFile 方法是这个 'show/' 请求
        return "/delete/" + uuid;
    }

    public static UploadFileVo FileStorageToUploadFileVo(FileStorage fileService) {
        String uuid = fileService.getUuid();
        return UploadFileVo.builder()
                .fileName(fileService.getName())
                .fileUUID(uuid)
                .url(getShowUuid(uuid))
                .downloadUrl(getDownloadUuid(uuid))
                .deleteUrl(getDeleteUuid(uuid))
                .type(new MimetypesFileTypeMap().getContentType(fileService.getName()))
                .build();
    }

}
